//拼多多面试题：ip 地址判断
#include <iostream>
#include <vector>

using namespace std;

vector<int> IpStringToVec(){

    std::string start_ip="192.168.10.10";
    std::vector<int> start_parts;
    size_t pos = 0;

    while ((pos = start_ip.find('.')) != std::string::npos) {
        start_parts.push_back(std::stoi(start_ip.substr(0, pos)));
        start_ip.erase(0, pos + 1);
    }
    start_parts.push_back(std::stoi(start_ip));
    return start_parts;
}
//区间判断；//拼多多面试题目
int Handle(std::vector<int> low,std::vector<int> up,std::vector<int> ip){
    for(size_t i=0;i<low.size();++i){
        if(ip[i]>low[i]){
            break;
        }else if(ip[i]==low[i]){
            continue;
        }else{
            return -1;
        }
    }

    for(size_t i=0;i<up.size();++i){
        if(ip[i]<up[i]){
            return 0;
        }else if(ip[i]==up[i]){
            continue;
        }else{
            return 1;
        }
    }
    return 0;
}

#include <iostream>
#include <sstream>
#include <string>
#include <iostream>
#include <sstream>
#include <vector>

uint64_t ipToUint64(const std::string& ipAddress) {
    uint64_t result = 0;
    std::istringstream iss(ipAddress);
    std::string token;
    int count = 0;

    while (std::getline(iss, token, '.')) {
        if (count >= 4) {
            throw std::invalid_argument("Invalid IPv4 address");
        }

        int num = std::stoi(token);
        if (num < 0 || num > 255) {
            throw std::invalid_argument("Invalid IPv4 address");
        }

        result |= static_cast<uint64_t>(num) << ((3 - count) * 8);
        count++;
    }

    if (count != 4) {
        throw std::invalid_argument("Invalid IPv4 address");
    }

    return result;
}




std::string numToIp(const std::string& numStr) {
    if (numStr.length() > 12) {
        return "输入数字过长，无法转换为 IP 地址";
    }
    long long num = std::stoll(numStr);
    int part1 = num >> 24 & 255;
    int part2 = num >> 16 & 255;
    int part3 = num >> 8 & 255;
    int part4 = num & 255;
    std::ostringstream oss;
    oss << part1 << "." << part2 << "." << part3 << "." << part4;
    return oss.str();
}